package com.fowler.humanresources.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fowler.humanresources.domain.User;
import com.fowler.humanresources.services.MemberService;

@Controller
@RequestMapping("/member/*")
public class MemberController {

	private MemberService memberService;
	
	@Autowired
	public MemberController(MemberService memberServcie){
		this.memberService = memberServcie;
	}
	@RequestMapping(value="join",method=RequestMethod.GET)
	public String memberJoin(Model model){
		model.addAttribute("member", new User());
		return "join";
	}
	@RequestMapping(value="base",method=RequestMethod.GET)
	public String baseLayout(Model model){
		model.addAttribute("member", new User());
		return "baselayout";
	}
	@RequestMapping(value="memberjoin", method=RequestMethod.POST)
	public String memberJoin(@ModelAttribute("member") User user, Model model){
		
		memberService.addUser(user);
		model.addAttribute(user);
		return "joinsuccess";
	}
}
